package leetcode.code2452;

import java.util.ArrayList;
import java.util.List;

public class Solution {
	public List<String> twoEditWords(String[] queries, String[] dictionary) {
		List<String> ans = new ArrayList<>();
		for (int i = 0; i < queries.length; i++) {
			String q = queries[i];
			for (int j = 0; j < dictionary.length; j++) {
				String d = dictionary[j];
				if (f(q, d) < 3) {
					ans.add(q);
					break;
				}
			}
		}
		return ans;
	}

	private int f(String q, String d) {
		int cnt = 0;
		for (int i = 0; i < q.length(); i++) {
			cnt += q.charAt(i) == d.charAt(i) ? 0 : 1;
		}
		return cnt;
	}
}
